/*
 * @Author: liuxinjia 15201611813@163.com
 * @Date: 2023-08-14 15:10:26
 * @LastEditors: liuxinjia 15201611813@163.com
 * @LastEditTime: 2023-08-15 10:03:59
 * @FilePath: \TicketPrintWebPlatformd:\当前项目\马上签金融机构前端项目\gitLab\MashangqianWebByBank\src\router\index.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import Vue from 'vue'
import VueRouter from 'vue-router'
import menu from '../views/menu.vue'
import { Message } from 'element-ui'
import information from '../views/information/information'
import MyMerchant from '../views/MyMerchant/MyMerchant'
import TransactionInquiry from '../views/TransactionInquiry/TransactionInquiry'
import LoanRecords from '../views/LoanRecords/LoanRecords'
import PastDueRecords from '../views/PastDueRecords/PastDueRecords'
import PaymentHistory from '../views/PaymentHistory/PaymentHistory'

Vue.use(VueRouter)






const routes = [
  { path: '/Login', name: 'Not1', component: () => import(/* webpackChunkName: "about" */ '../views/Login.vue') }, // route level code-splitting
  // this generates a separate chunk (about.[hash].js) for this route
  // which is lazy-loaded when the route is visited. component: () =>   import(/* webpackChunkName: "about" */ '../views/Login.vue'),   },
  {
    path: '/', name: 'menu', component: menu, redirect: (to) => {   // 方法接收目标路由作为参数
      // return 重定向的字符串路径/路径对象
      // return { path: '/HomePage', query: { q: to.params.searchText } }
      return { path: '/Login', query: { q: to.params.searchText } }
    }, children: [
      { path: 'information', component: information, name: '首页' },
      { path: 'MyMerchant', component: MyMerchant, name: '我的客户' },
      { path: 'TransactionInquiry', component: TransactionInquiry, name: '交易查询' },
      { path: 'LoanRecords', component: LoanRecords, name: '放款记录' },
      { path: 'PastDueRecords', component: PastDueRecords, name: '逾期记录' },
      { path: 'PaymentHistory', component: PaymentHistory, name: '还款记录' },
    ],
  },
]
const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes,
})
router.beforeEach((to, from, next) => {
  let token = sessionStorage.getItem('token')
  // 检测是否为纯数字  纯数字跳转到签收页面
  if (!isNaN(Number(to.fullPath.slice(1, to.fullPath.length)))) {
    next('/App/Receipt?Id=' + to.fullPath.slice(1, to.fullPath.length))
  } else if (to.path == '/information' && from.path == '/Login') {
    next()
  } else if (to.path == '/information' && from.path == '/' && !token) {
    next('/Login')
    // } else if (routerList.findIndex((item) => item == to.path) !== -1) {
  } else if (to.name && to.name.indexOf('Not') >= 0) {
    console.log('进入页面')
    next()
  } else {
    if (to.fullPath.indexOf('token=') !== -1) {
      token = to.fullPath.split('token=')[1]
    }
    if (!token) {
      Message.error('登录信息失效,请重新登录')   // next('/Login')   window.open('http://msq.yoojet.com/Login?tap=1', '_self')   return
    } next()
  }
})

export default router
